package server.entity.auth;


import cn.hutool.json.JSONObject;
import org.springframework.stereotype.Component;

@Component
@SuppressWarnings("unused")
public class AuthResponse {
    private final JSONObject json = new JSONObject();

    public AuthResponse setCode(int code) {
        json.putOpt("code", code);
        return this;
    }

    public AuthResponse setMessage(CharSequence msg) {
        json.putOpt("message", msg);
        return this;
    }

    public AuthResponse setData(Object obj) {
        json.putOpt("data", obj);
        return this;
    }

    public JSONObject setResponseType(AuthResponseType type) {
        if (!json.isEmpty()) {
            json.clear();
        }
        json.putOpt("code", type.getCode())
                .putOpt("msg", type.getMsg());
        return json;
    }

    public JSONObject getResult() {
        return json;
    }

    @Override
    public String toString() {
        return json.toString();
    }

}
